<template>
  <div>
    <!-- 标题 -->
    <header-search ref="header" class="header" left-type="menu" :left-menu="menuList2" @activeMenu="activeMenu">
      <!-- <el-button v-if="(auths.indexOf('*') > -1 || goodsUnitList.indexOf('UnitSyncKingdeeUnit') > -1) && activeName == 'unit'
        " slot="right" size="mini" type="primary" icon="unit" @click="handleAdd()">同步</el-button>
      <el-button v-if=" (auths.indexOf('*') > -1 || goodsUnitList.indexOf('UnitSyncKingdeeUnit') <= -1) && activeName == 'unit'
        " slot="right" size="mini" type="primary" icon="el-icon-plus" @click="addCategory()">新增产品单位</el-button>
      <el-button v-if="activeName == 'spec'" slot="right" size="mini" type="primary" icon="el-icon-plus"
        @click="handleSpec()">新增规格</el-button> -->
    </header-search>
    <!-- 内容 -->
    <!-- <el-card class="content scrollbar"> -->
    <!-- 药品档案 -->
    <archives v-show="activeName === 'archives'" ref="archives" />
    <!-- 药品类型 -->
    <drugType v-show="activeName === 'drugType'" ref="drugType" />
    <!-- 药品分类 -->
    <classification v-show="activeName === 'classification'" ref="classification" />
    <!-- 药品单位 -->
    <company v-show="activeName === 'company'" ref="company" />

    <!-- </el-card> -->
  </div>
</template>

<script>
class Auth {
  'GoodsUnitList' = '';
  'SpecUnitList' = '';
}
import HeaderSearch from '@/components/HeaderSearch/';
import archives from './archives';
import drugType from './drugType';
import classification from './classification';
import company from './company';
// import { mapGetters } from 'vuex';
export default {
  name: 'Drugs',
  components: {
    HeaderSearch,
    archives,
    drugType,
    classification,
    company
  },
  data () {
    return {
      activeName: 'archives',
      leftMenu: [],
      goodsUnitList: '',
      specUnitList: '',
      auths: '',
      menuList1: [
        {
          name: 'archives',
          label: '药品档案'
        },
        {
          name: 'drugType',
          label: '药品类型',
          code: '001005007009'
        },
        {
          name: 'classification',
          label: '药品分类',
          code: '001005007010'
        },
        {
          name: 'company',
          label: '药品单位',
          code: '001005007015'
        }
      ],
      menuList2: [],
      auth: new Auth()
    };
  },
  computed: {
    // ...mapGetters(['permission'])
  },
  mounted () {
    this.activeMenu('archives');
    this.initMenu();
  },
  methods: {
    initMenu () {
      let menuList2 = [];
      this.menuList1.forEach(ele => {
        if (!ele.code) {
          menuList2.push(ele);
        }
      });
      this.menuList2 = menuList2;
      // console.log(this.pageLimits);
      // this.$nextTick(() => {
      //   if (typeof this.pageLimits === 'object') {
      //     this.auth = this.pageLimits;
      //     if (this.pageLimits['GoodsUnitList']) this.leftMenu.push(this.menuList[0]); this.goodsUnitList = this.pageLimits['GoodsUnitList'];
      //     if (this.pageLimits['SpecUnitList']) this.leftMenu.push(this.menuList[1]); this.specUnitList = this.pageLimits['SpecUnitList'];
      //     console.log(this.goodsUnitList, this.specUnitList);
      //   } else {
      //     if (this.pageLimits.indexOf('*') > -1) this.leftMenu.push(...this.menuList);
      //     this.auth['GoodsUnitList'] = '*';
      //     this.auth['SpecUnitList'] = '*';
      //     this.auths = '*';
      //   }
      //   this.activeMenu(this.leftMenu[0].name);
      // });
    },
    // 点击菜单
    activeMenu (activeName) {
      this.activeName = activeName;
      this.leftMenu = this.leftMenu.map((val) => {
        const { check, unchecked } = val;
        return {
          ...val,
          icon: val.name === activeName ? check : unchecked
        };
      });
      this.$refs[activeName].getList();
    }
    // handleSpec () {
    //   this.$refs[this.activeName].addCategory('新建');
    // },
    // // 新增操作产品单位
    // addCategory () {
    //   this.$refs[this.activeName].addCategory('新建');
    // },
    // // 新增操作单位规格
    // handleAdd () {
    //   this.$refs[this.activeName].hint('', '此操作将同步金蝶单位列表');
    // }
  }
};
</script>

<style lang="scss" scoped>
.content {
  height: calc(100% - 70px);
  overflow-y: hidden;
}
.content:hover {
  overflow-y: auto;
}
</style>
